*******************
**** Table B13 ****
*******************

use "$data/paymentdata_ready" , clear


drop if treatmentall==.

keep if t==1



xtile highpreratio = preratio, nq(2)
replace highpreratio=highpreratio-1 if preratio!=.

egen preratiow1mean=mean(preratiow1)
replace preratiow1=preratiow1-preratiow1mean
drop preratiow1mean

rename personalcontactdummy pc
  
foreach var in  preratiow1 collectiv highpreratio pc highquality missquality highvisible missvisible lowquality housetype {
gen  `var'treatmentidentityd2=treatmentidentityd2*`var'
gen  `var'treatmentidentityd3=treatmentidentityd3*`var'
gen  `var'treatmentidentityd4=treatmentidentityd4*`var'
}

log using "$output/table b13", replace


** Column 1 **
capture program drop Ey_boot
program define Ey_boot, eclass
twopm interventionratiow1 treatmentidentityd2* treatmentidentityd3* treatmentidentityd4* collectiv* pc* highvisible* missvisible* preratiow1* lastdebt_demeanedw1 prepaymentsmadedummy*  i.team i.firststicker, firstpart(probit) secondpart(regress) 
margins, dydx(treatmentidentityd2* treatmentidentityd3* treatmentidentityd4* collectiv* pc* highvisible* preratiow1*) nose post
end
bootstrap _b, seed(346) reps(1000): Ey_boot
estimates store e

test collectivtreatmentidentityd2=collectivtreatmentidentityd3
test collectivtreatmentidentityd2=collectivtreatmentidentityd4

test pctreatmentidentityd2=pctreatmentidentityd3
test pctreatmentidentityd2=pctreatmentidentityd4

test highvisibletreatmentidentityd2=highvisibletreatmentidentityd3
test highvisibletreatmentidentityd2=highvisibletreatmentidentityd4


** Column 2 **
capture program drop Ey_boot
program define Ey_boot, eclass
twopm postratiow1 treatmentidentityd2* treatmentidentityd3* treatmentidentityd4* collectiv* pc* highvisible* preratiow1* lastdebt_demeanedw1 prepaymentsmadedummy* missvisible* i.team i.firststicker, firstpart(probit) secondpart(regress) 
margins, dydx(treatmentidentityd2* treatmentidentityd3* treatmentidentityd4* collectiv* pc* highvisible* preratiow1*) nose post
end
bootstrap _b, seed(346) reps(1000): Ey_boot



** Column 3 **
capture program drop Ey_boot
program define Ey_boot, eclass
twopm  ratiow1 treatmentidentityd2* treatmentidentityd3* treatmentidentityd4* collectiv* pc* highvisible* preratiow1* lastdebt_demeanedw1 prepaymentsmadedummyB* missvisible* i.team i.firststicker, firstpart(probit) secondpart(regress) 
margins, dydx(treatmentidentityd2* treatmentidentityd3* treatmentidentityd4* collectiv* pc* highvisible* preratiow1*) nose post
end
bootstrap _b, seed(346) reps(1000): Ey_boot

log close
